package com.example.mvpdemo.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
/**
 * name 视图层
 * desc 初始化视图
 * author Sy
 * email 564379992@qq.com
 * created 2020/5/6 15:20
 */
public abstract class BaseActivity<P extends BasePresenter, CONTRACT> extends AppCompatActivity implements View.OnClickListener {

    public abstract CONTRACT getContract();
    /**
     *  定义P层，必须是BasePresenter的子类才可以传 <P extends BasePresenter>;
     */
    public P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayoutId());
        initView();
        initData();
        initListener();
        mPresenter = getmPresenterInstance();
        mPresenter.bindView(this);
    }

    /**
     * 让子类去实例化P层
     * @return
     */
    public abstract P getmPresenterInstance();


    /**
     * 设置视力ID
     * @return
     */
    public abstract int setLayoutId();

    /**
     * 初始化视图
     */
    public abstract void initView();

    /**
     * 设置数据
     */
    public abstract void initData();

    /**
     * 监听点击
     */
    public abstract void initListener();

    /**
     * 销毁
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        destory();
        mPresenter.unBindView();
    }

    public abstract void destory();


}
